﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TK_SanPham.ascx.cs" Inherits="Bussiness.View.BackEnd.User_Control.TK_SanPham" %>
<ext:Window ID="tk_SanPham" runat="server" Icon="Group" Title="Tìm kiếm sản phẩm" Width="700" Height="550" Hidden="true" Layout="FormLayout" LabelAlign="Left"
            PaddingSummary="10px 10px 0 10px" IDMode="Static">
            <Items>
                <ext:FieldSet ID="FieldSet4" runat="server" Layout="ColumnLayout" Title="Thông tin tìm kiếm"
                    PaddingSummary="10px 5px 0 5px" Height="100">
                    <Items>
                        <ext:Container ID="Container7" runat="server" LabelAlign="Right" Layout="FormLayout"
                            ColumnWidth=".5">
                            <Items>
                                <ext:TextField ID="tk2_tenHang" runat="server" FieldLabel="Tên sản phẩm" AnchorHorizontal="100%"
                                    LabelAlign="Right" IDMode="Static" />
                            </Items>
                            <Items>
                                <ext:TextField ID="tk2_maSP" runat="server" FieldLabel="Mã sản phẩm" AnchorHorizontal="100%"
                                    LabelAlign="Right" IDMode="Static" />
                            </Items>
                        </ext:Container>
                        <ext:Container ID="Container8" runat="server" LabelAlign="Right" Layout="FormLayout"
                            ColumnWidth=".5">
                            <Items>
                                <ext:SelectBox ID="tk2_loaiSP" runat="server" FieldLabel="Loại sản phẩm" AnchorHorizontal="100%"
                                    DataIndex="Status" IDMode="Static" ValueField="ID" DisplayField="Name">
                                    <Store>
                                        <ext:Store ID="LoaiSP_Store" runat="server" IDMode="Static">
                                            <Reader>
                                                <ext:ArrayReader IDProperty="ID">
                                                    <Fields>
                                                        <ext:RecordField Name="ID" Type="int" Mapping="ID" />
                                                        <ext:RecordField Name="Name" Type="String" Mapping="Name" />
                                                    </Fields>
                                                </ext:ArrayReader>
                                            </Reader>
                                        </ext:Store>
                                    </Store>
                                </ext:SelectBox>
                            </Items>
                            <Items>
                                <ext:Button ID="Button8" runat="server" Text="Tìm kiếm" FieldLabel=" " LabelSeparator=" "
                                    Icon="Find">
                                    <DirectEvents>
                                        <Click OnEvent="search_SanPham"></Click>
                                    </DirectEvents>
                                </ext:Button>
                            </Items>
                        </ext:Container>
                    </Items>
                </ext:FieldSet>
            </Items>
            <Items>
                <ext:GridPanel ID="tk_SP_Grid" IDMode="Static" runat="server" Height="400" AutoScroll="true"
                    Region="Center">
                    <Store>
                        <ext:Store ID="tk_SP_Store" runat="server" AutoDataBind="true" SkipIdForNewRecords="false">
                            <Reader>
                                <ext:JsonReader IDProperty="ID">
                                    <Fields>
                                        <ext:RecordField Name="ID" Type="String" Mapping="ID" />
                                        <ext:RecordField Name="Name" Type="String" Mapping="Name" />
                                        <ext:RecordField Name="Code" Type="String" Mapping="Code" />
                                        <ext:RecordField Name="Unit" Type="String" Mapping="Unit" />
                                        <ext:RecordField Name="HaveSize" Type="Boolean" Mapping="HaveSize" />
                                        
                                        <ext:RecordField Name="PriceImport" Type="Int" Mapping="PriceImport" />
                                        <ext:RecordField Name="PriceExprort" Type="Int" Mapping="PriceExprort" />
                                        <ext:RecordField Name="DateImport" Type="Date" Mapping="DateImport" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <ColumnModel ID="ColumnModel3" runat="server" AutoDataBind="true">
                        <Columns>
                            <ext:RowNumbererColumn />
                            <ext:Column ColumnID="ID" Header="Mã" DataIndex="ID" Hidden="true" />
                            <ext:Column ColumnID="HaveSize"  DataIndex="HaveSize" Hidden="true" />
                            <ext:Column Header="Mã sản phẩm" DataIndex="Code" AutoDataBind="true" Width="70" MenuDisabled="True" />
                            <ext:Column Header="Tên" DataIndex="Name" AutoDataBind="true" Width="150" />
                            <ext:Column Header="Đơn vị tính" DataIndex="DonViTinh" AutoDataBind="true" Width="90"
                                MenuDisabled="True" />
                               
                            <ext:NumberColumn Header="Gía bán" DataIndex="PriceExprort" AutoDataBind="true" MenuDisabled="True"
                                Format="0,00" />
                            <ext:DateColumn Header="Ngày cập nhật" DataIndex="DateImport" AutoDataBind="true"
                                MenuDisabled="True" Format="dd/MM/yyyy" />
                        </Columns>
                    </ColumnModel>
                    <SelectionModel>
                            <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1"  runat="server">
                    </ext:CheckboxSelectionModel>
            </SelectionModel>
                    <Listeners>
                        <Command Handler="detail(command, record.data.ID)" />
                    </Listeners>
                    <Buttons>
                        <ext:Button runat="server" Text="Chọn" ID="Button6" Icon="Add">
                            <Listeners>
                <Click Fn="Select"  />
            </Listeners>
                        </ext:Button>
                        <ext:Button runat="server" Text="Đóng" ID="Button7" Icon="Cancel">
                              <Listeners><Click fn="close_SP"/></Listeners>
                        </ext:Button>
                    </Buttons>
                </ext:GridPanel>
            </Items>
        </ext:Window>
        <script language="javascript">
            function Select() {
                var records = Ext.getCmp('tk_SP_Grid').getSelectionModel().getSelections();
                var grid = Ext.getCmp('DS_SanPham_Grid');
                var i = 0;
                for (i = 0; i < records.length; i++) {

                    grid.insertRecord(0);
                    grid.getView().refresh();
                    grid.getView().focusRow(0);
                    grid.getSelectionModel().selectRow(0);
                    var record1 = grid.getSelectionModel().getSelected();

                    record1.data['CodeProduct'] = records[i].data['Code'];
                    record1.data['NameProduct'] = records[i].data['Name'];
                    record1.data['Unit'] = records[i].data['Unit'];
                    record1.data['ID'] = records[i].data['ID'];

                    record1.data['SinglePrice'] = records[i].data['PriceExprort'];
                    record1.data['SingleImportPrice'] = records[i].data['PriceImport'];
                    record1.data['HaveSize'] = records[i].data['HaveSize'];
                    


                    Ext.getCmp('DS_SanPham_Grid').getView().refresh();

                }

               // if (records.length == 0) { Ext.Msg.alert('Lỗi', 'Bạn phải chọn sản phẩm.'); return false }

                Ext.getCmp('tk_SanPham').setVisible(false);







            }
        </script>